package com.soulkun.smarthome.ui.main.scene.adapter

import android.content.Context
import androidx.core.content.res.ResourcesCompat
import androidx.databinding.ObservableArrayList
import androidx.databinding.ViewDataBinding
import com.soulkun.smarthome.R
import com.soulkun.smarthome.databinding.AppRecycleItemMainSceneAutoExpressionListBinding
import com.soulkun.smarthome.logic.enum.ExpressionEnum
import com.soulkun.smarthome.logic.model.ExpressionModel
import soulkun.library.mvvm.adapter.BaseDataBindingRecyclerViewAdapter

class AppMainSceneAutoExpressionListAdapter(context: Context, modelList: ObservableArrayList<ExpressionModel>): BaseDataBindingRecyclerViewAdapter<ExpressionModel>(context, modelList) {

    override fun getContentLayoutResId(): Int {
        return R.layout.app_recycle_item_main_scene_auto_expression_list
    }


    override fun setContentViewHolderCreateListener(binding: ViewDataBinding) {
    }

    override fun setContentViewHolderBindListener(binding: ViewDataBinding, dataPosition: Int) {
        val data = dataList[dataPosition]
        (binding as AppRecycleItemMainSceneAutoExpressionListBinding).run {
            when (data.expressionEnum) {
                ExpressionEnum.Condition -> {
                    when (data.expressionId) {
                        0 -> { //天气
                            ivMainSceneAutoExpressionListIconExpression.setImageDrawable(
                                ResourcesCompat.getDrawable(
                                    context.resources,
                                    R.drawable.app_main_expression_list_icon_condition_weather,
                                    null
                                )
                            )
                        }
                        1 -> { //定时
                            ivMainSceneAutoExpressionListIconExpression.setImageDrawable(
                                ResourcesCompat.getDrawable(
                                    context.resources,
                                    R.drawable.app_main_expression_list_icon_condition_time,
                                    null
                                )
                            )
                        }
                        2 -> { //设备状态
                            ivMainSceneAutoExpressionListIconExpression.setImageDrawable(
                                ResourcesCompat.getDrawable(
                                    context.resources,
                                    R.drawable.app_main_expression_list_icon_condition_status,
                                    null
                                )
                            )
                        }
                    }
                }
                ExpressionEnum.To -> {
                    ivMainSceneAutoExpressionListIconExpression.setImageDrawable(
                        ResourcesCompat.getDrawable(
                            context.resources,
                            R.drawable.app_main_scene_expression_list_icon_to,
                            null
                        )
                    )
                }
                ExpressionEnum.Job -> {
                    when(data.expressionId){
                        0 -> {
                            ivMainSceneAutoExpressionListIconExpression.setImageDrawable(
                                ResourcesCompat.getDrawable(
                                    context.resources,
                                    R.drawable.app_main_expression_list_icon_job_device,
                                    null
                                )
                            )
                        }
                        1 -> {
                            ivMainSceneAutoExpressionListIconExpression.setImageDrawable(
                                ResourcesCompat.getDrawable(
                                    context.resources,
                                    R.drawable.app_main_expression_list_icon_job_notification,
                                    null
                                )
                            )
                        }
                    }
                }
            }
        }
    }

}